const readline = require('readline');
const rl = readline.createInterface({ input: process.stdin });
let input = [];

rl.on('line', line => input.push(line.trim()));
rl.on('close', () => {
  let idx = 0;
  const T = parseInt(input[idx++]);

  for (let t = 0; t < T; t++) {
    const [n, m] = input[idx++].split(' ').map(Number);
    const records = input[idx++].split(' ').map(Number);
    
    const parked = new Set();
    let maxCapacity = 0;
    
    for (const record of records) {
      if (record > 0) {
        // 车辆驶入
        parked.add(record);
      } else {
        // 车辆驶出：如果车不在停车场，说明进入记录缺失
        const carId = -record;
        if (!parked.has(carId)) {
          parked.add(carId);
        }
        // 在移除前更新最大容量
        maxCapacity = Math.max(maxCapacity, parked.size);
        parked.delete(carId);
      }
      // 驶入后也需要更新最大容量
      maxCapacity = Math.max(maxCapacity, parked.size);
    }
    
    console.log(maxCapacity);
  }
});

